ExploreByTouchHelper

(SESL variant) ExploreByTouchHelper is a utility class for implementing accessibility support in custom Views that represent a collection of View-like logical items. It extends AccessibilityNodeProviderCompat and simplifies many aspects of providing information to accessibility services and managing accessibility focus.

Clients should override abstract methods on this class and attach it to the host view using setAccessibilityDelegate.

The host view should also override the events in the following code snippet so that the view's logical items are detected properly by the framework:

class MyCustomView extends View {
    private MyExploreByTouchHelper mExploreByTouchHelper;

    public MyCustomView(Context context, ...) {
        ...
        mExploreByTouchHelper = new MyExploreByTouchHelper(this);
        ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper);
    }

    @Override
    public boolean dispatchHoverEvent(MotionEvent event) {
      return mHelper.dispatchHoverEvent(this, event)
          || super.dispatchHoverEvent(event);
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
      return mHelper.dispatchKeyEvent(event)
          || super.dispatchKeyEvent(event);
    }

    @Override
    public void onFocusChanged(boolean gainFocus, int direction,
        Rect previouslyFocusedRect) {
      super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
      mHelper.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
    }
}

Constructors

Link copied to clipboard
constructor(@NonNull host: @NonNull View)
Constructs a new helper that can expose a virtual view hierarchy for the specified host view.

Properties

Link copied to clipboard
val HOST_ID: Int = -1
Virtual node identifier value for the host view's node.
Link copied to clipboard
val INVALID_ID: Int = -2147483648
Virtual node identifier value for invalid nodes.

Functions

Link copied to clipboard
Attempts to clear keyboard focus from a virtual view.
Link copied to clipboard
fun dispatchHoverEvent(@NonNull event: @NonNull MotionEvent): Boolean
Delegates hover events from the host view.
Link copied to clipboard
fun dispatchKeyEvent(@NonNull event: @NonNull KeyEvent): Boolean
Delegates key events from the host view.
Link copied to clipboard
Returns the virtual view ID for the currently accessibility focused item.
Link copied to clipboard
Notifies the accessibility framework that the properties of the parent view have changed.
Link copied to clipboard
fun invalidateVirtualView(virtualViewId: Int)
fun invalidateVirtualView(virtualViewId: Int, changeTypes: Int)
Notifies the accessibility framework that the properties of a particular item have changed.
Link copied to clipboard
fun onFocusChanged(gainFocus: Boolean, direction: Int, @Nullable previouslyFocusedRect: @Nullable Rect)
Delegates focus changes from the host view.
Link copied to clipboard
Attempts to give keyboard focus to a virtual view.
Link copied to clipboard
fun sendEventForVirtualView(virtualViewId: Int, eventType: Int): Boolean
Populates an event of the specified type with information about an item and attempts to send it up through the view hierarchy.
Link copied to clipboard
fun setBoundsInScreenFromBoundsInParent(@NonNull node: @NonNull AccessibilityNodeInfoCompat, @NonNull boundsInParent: @NonNull Rect)
Calculates and assigns screen-relative bounds based on bounds in parent.